﻿using Bids.Core.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using Telerik.OpenAccess.Metadata;
using Telerik.OpenAccess.Metadata.Fluent;
namespace Bids.Core.DomainObjects
{
	/// <summary>
	/// 投稿列表
	/// </summary>
	[Serializable]
    public class UsedFor : IEntity
	{
        
		/// <summary>
		/// 
		/// </summary>
        public virtual int ID { set; get; }
		/// <summary>
		/// 名称
		/// </summary>
        public virtual string Name { set; get; }

        public virtual IList<Task> Tasks { get; set; }

        public static MappingConfiguration<UsedFor> CreateConfiguration()
        {
            var threadMapping = new MappingConfiguration<UsedFor>();
            threadMapping.MapType(t => new
            {
                t.ID,
                t.Name
            }).ToTable("UsedFor");
            threadMapping.HasProperty(t => t.ID).IsIdentity(KeyGenerator.Autoinc);
            threadMapping.HasAssociation(t => t.Tasks).WithOpposite(d => d.UsedFor).MapJoinTable("TaskUsedFor",
                (t, d) => 
                    new 
                    {
                        TaskId = d.ID,
                        UsedForId = t.ID
                    }
                );

            return threadMapping;
        }

	}
}

